# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/5/18 1:04
# @Author   : Robot-Zsj
"""
description: 
"""
from itertools import chain


def convert(s, numRows):
    r = numRows
    if r == 1 or r >= len(s):
        return s
    mat = [[] for _ in range(r)]
    t, x = r * 2 - 2, 0
    for i, ch in enumerate(s):
        mat[x].append(ch)
        x += 1 if i % t < r - 1 else -1
    return ''.join(chain(*mat))


res = convert("PAYPALISHIRING", 3)
print(res)
